package battleship.cxbr;

import java.util.ArrayList;

import battleship.emss.*;

public class AvoidContext extends Context
{
	protected double h;
	protected double st;
	
	public AvoidContext(String n,CxBRAgent a)
	{
		super(n,a);
	}
	
	//How to get here from above
	public double ParentRule(double Time)
	{
		int tx = (int)(Agent.status.x + 3 * Math.cos(Agent.status.h));
		int ty = (int)(Agent.status.y + 3 * Math.sin(Agent.status.h));
		
		if(WorldMap.GetOccupied(tx,ty) != WorldMap.EMPTY){
			// System.out.println("Going to hit something: " + tx + " " + ty);
			return 1.0;
		}
		return 0.0;
	}
	//How to get here from side
	public double SiblingRule(double Time)
	{
		return 0.0;
	}
	
	//Things to do when just entering
	public void Initialize(double Time)
	{
		//Record When the hit happened
		st = Time;
		//current angle when hit happened
		h = Agent.status.h-Math.PI;
	}

	
	//What do actually do
	public void Action(double Time)
	{
		Agent.status.status = Name + " " + (int)(Time - st)+ " " + h;
		Agent.actions.clear();
		
		if(Time - st < 300){
			Agent.actions.add(new Move(h, -6.0));
		}
		else{
			Agent.actions.add(new Move(h, 12.0));
		}
		return;
	}
	
}

